/*
 * Copyright (C) 2001-2005 Pleasant nightmare studio
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 *
 * See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */
package org.pleasantnightmare.noraxidium.collision;

import org.apache.log4j.Logger;

import java.util.LinkedList;
import java.util.List;

/**
 * Collection of other CollisionBound implementations. All of them contain position
 * relative to this bound position, and all of them are checked against collision.
 * <p/>
 * CollisionResult will return exact bound hit.
 *
 * @author deus
 * @version 1.0
 * @since Jul 12, 2010 9:44:07 AM
 */
public class CompositeBound implements CollisionBound {
  private static final Logger LOGGER = Logger.getLogger(CompositeBound.class);

  private List<CollisionBound> bounds;

  public CompositeBound() {
    bounds = new LinkedList<CollisionBound>();
  }

  public void addCollisionBound(CollisionBound collisionBound) {
    bounds.add(collisionBound);
  }

  public void removeCollisionBound(CollisionBound collisionBound) {
    bounds.remove(collisionBound);
  }

  @Override public CollisionResult calculateAgainst(RectBound rectBound) {
    CollisionResult result = new CollisionResult();
    for (CollisionBound bound : bounds) {
      CollisionResult collisionResult = bound.calculateAgainst(rectBound);
      if (collisionResult.isCollisionDetected()) {
        for (CollisionBound collisionBound : collisionResult.getBounds())
          result.addBound(collisionBound, collisionResult.getExitVector(collisionBound));
      }
    }

    return result;
  }

  @Override public CollisionType getCollisionType() {
    return CollisionType.COMPOSITE;

  }
}
